package org.lex.dbq.view.browser;

import org.eclipse.swt.widgets.Composite;
import org.lex.dbq.DBQApplication;
import org.lex.dbq.model.bo.JdbcUrlTemplate;
import org.lex.dbq.model.service.ServiceFactory;
import org.lex.dbq.view.Actions;
import org.lex.dbq.view.template.TemplateDialog;

public class TemplatePane extends AbstractBrowser<JdbcUrlTemplate> {

	public TemplatePane(Composite parent) {
		super(parent, ServiceFactory.getTemplateService());
	}

	@Override
	public void connect() {
		String name = this.getSelectedObjectName();
		log.debug("open template: " + name);
		DBQApplication app = DBQApplication.getApplication();
		app.getOperator().showConnectTemplateDialog(name);
	}

	public void add() {
		this.getActionService().getActionMap().get(Actions.ADD_TEMPLATE).run();
	}

	@Override
	public void edit() {
		String name = this.getSelectedObjectName();
		JdbcUrlTemplate edit = ServiceFactory.getTemplateService().getByName(name);
		TemplateDialog.showEdit(getShell(), edit);
	}
}
